import Board from '../board'

export default function Convert(board: Board, points: Array<Array<any>>): Array<Array<number>> {
  let result = []
  for (let i = 0; i < points.length; i++) {
    result.push([ConvertToNumber(board.width, points[i][0]), ConvertToNumber(board.height, points[i][1])])
  }
  return result
}

function ConvertToNumber(size: number, value: string | number) {
  let num = Number(value)
  if (num) {
    return num > 0 ? num : size + num
  } else if (typeof value == 'string') {
    if (value == 'center') return size / 2
    else if (value.match('%')) return Number(value.replace('%', '')) / 100
    else console.error('数据类型错误')
  } else console.error('数据类型错误')
}
